home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / dwyer2 / iterline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  825 b   |  45 lines

  1. /* Listing 5        Iterative, Fixed Point Line Routine */
  2.  
  3. /*
  4.     This function relies on the Borland graphics library
  5. */
  6.  
  7.  
  8. #include <graphics.h>
  9.  
  10.  
  11. #define FixedPointShiftAmount 8
  12.  
  13. #define FPToInteger( FP )  ( FP >> FixedPointShiftAmount )
  14. #define IntegerToFP( Integer )  ( Integer << FixedPointShiftAmount )
  15.  
  16.  
  17. typedef long FixedPnt;
  18.  
  19.  
  20. void IterativeLine( short x1, short y1, short x2, short y2 )
  21. {
  22.     /* This dt gives 128 steps */
  23.     FixedPnt t, dt = 1 << ( FixedPointShiftAmount - 6 );
  24.     FixedPnt x, y, dx, dy;
  25.  
  26.     /* Compute FixedPnt deltas */
  27.     dx = ( x2 - x1 ) * dt;
  28.     dy = ( y2 - y1 ) * dt;
  29.  
  30.     /* Initial values */
  31.     x = IntegerToFP( (long) x1 );
  32.     y = IntegerToFP( (long) y1 );
  33.  
  34.     putpixel( x1, y1, 15 );
  35.  
  36.     for( t = 0; t < IntegerToFP( 1 ); t += dt )
  37.     {
  38.         x += dx;
  39.         y += dy;
  40.         
  41.         putpixel( FPToInteger( x ), FPToInteger( y ), 14 );
  42.     }
  43. }
  44.  
  45.